<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko-KR" lang="ko-KR">
    <head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<script src="mootools.js" type="text/javascript" ></script>
	<script src="init.js" type="text/javascript" ></script>
	<script src="cmd.js" type="text/javascript" ></script>
	<title>daush</title>
	<style>
	    * { border:0px; margin:0px; padding:0px;}
	</style>
    </head>
    <body>
	<select id="category">
	    <option value="vclip">동영상</option>
	    <option value="image">이미지</option>
	    <option value="cafe">카페</option>
	    <option value="news">뉴스</option>
	    <option value="blog">블로그</option>
	    <option value="board">게시판</option>
	    <option value="book">책</option>
	</select>
	<input id="query" />
	<button id="button" />검색</button>
	<div id="view" /></div>
	<script>
var obj = {
  init : function()
  {
    obj.query = document.getElementById('query');
    obj.button = document.getElementById('button');
    obj.view = document.getElementById('view');
	obj.category = document.getElementById('category'); 
    obj.button.onclick = obj.pingSearch;
  },
  pingSearch : function()
  {
    if (obj.query.value)
    {
      obj.search = document.createElement('script');
      obj.search.type ='text/javascript';
      obj.search.charset ='utf-8';
      obj.search.src = 'http://apis.daum.net/search/'+obj.category.value+'?apikey=457826efc72b71ca78527f24e9d2cfee33b493f1&output=json&callback=obj.pongSearch&q=' + encodeURI(obj.query.value);
      document.getElementsByTagName('head')[0].appendChild(obj.search);
    }
  },
  pongSearch : function(z)
  {
    obj.view.innerHTML = '';
    for (var i = 0; i < z.channel.item.length; i++)
    {
      var li = document.createElement('li');
      var a = document.createElement('a');
      var p = document.createElement('p');
      a.href = z.channel.item[i].link;
      a.innerHTML = obj.escapeHtml(z.channel.item[i].title);
      p.innerHTML =  obj.escapeHtml(z.channel.item[i].description);
      
      li.appendChild(a);
      li.appendChild(p);
      obj.view.appendChild(li);
    }
  },
  escapeHtml : function(str) 
  {
    str = str.replace(/&amp;/g, "&");
    str = str.replace(/&lt;/g, "<");
    str = str.replace(/&gt;/g, ">");
    return str;
  }
};
window.onload = function()
{
  obj.init();
};
	</script>
    </body>
</html>
